<?php

namespace addons\xcrontab;

use addons\xcrontab\library\RunStatus;
use app\common\library\Menu;
use Exception;
use think\Addons;

/**
 * 插件
 */
class Xcrontab extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {


        $menu = [
            [
                'name'    => 'xcrontab',
                'title'   => '定时任务增强',
                'icon'    => 'fa fa-tasks',
                'sublist' => [
                    [
                        'name' => 'xcrontab/info',
                        'title' => '状态信息',
                        'icon' => 'fa fa-info',
                        'remark'  => '定时任务请再官方定时任务插件添加任务，虚拟主机不支持shell命令定时任务',
                    ]
                ]
            ]
        ];

        $menu = [
            [
                'name' => 'xcrontab',
                'title' => '跨平台定时任务增强',
                'icon' => 'fa fa-tasks',
                'sublist' =>
                [
                    [
                        'name' => 'xcrontab/info',
                        'title' => '状态信息',
                        'icon' => 'fa fa-info',
                        'weigh' => 0,
                        'remark'  => '定时任务请再官方定时任务插件添加任务，虚拟主机不支持shell命令定时任务',
                        'sublist' =>
                        [
                            [
                                'name' => 'xcrontab/info/index',
                                'title' => '查看',
                                'icon' => 'fa fa-circle-o',
                                'weigh' => 0,
                            ],
                        ]
                    ],
                ],
            ],
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('xcrontab');
        RunStatus::clean();
        return true;
    }

    /**
     * 插件启用方法
     */
    public function enable()
    {
        Menu::enable('xcrontab');
    }

    /**
     * 插件禁用方法
     */
    public function disable()
    {
        RunStatus::clean();
        Menu::disable('xcrontab');
    }
}
